var d = document;

function refresh_username(selected_username, selected_user_id) {
    opener.document.getElementById("username").value = selected_username;
    opener.document.getElementById("user_id").value = selected_user_id;
    opener.focus();    
    window.close();
}

function insRow(tabl, position, row_id, color_) {
    var arow = tabl.insertRow(position);
    arow.id = "row"+row_id;
    arow.bgColor = color_;
    return arow;
}

function insCell(arow, aCaption, className, aWidth, aColor) {
var cell = arow.insertCell(0);
    cell.className = className;
    cell.width = aWidth;
    cell.height = 22;
    cell.bgColor = aColor;
    cell.innerHTML = aCaption;

	return cell;
}

function add_biblio(biblio_name, biblio_id) {
    var findElement = opener.document.getElementById("tbadd");
    var arow = insRow(findElement, 2, biblio_id, "#C5CED9");

    var inputBx = '<input type="checkbox" value="'+biblio_id+'" name="del_me[]" '+
        'class="BoxCenter" onClick="javascript:delrows();" />'+
        '<input type="hidden" id="biblio_id" name="biblio_id" value="'+biblio_id+'" />';
        //'<input type="hidden" id="biblio_id" name="biblio_id['+biblio_id+']" value="'+biblio_id+'" />';

    insCell(arow, inputBx, "headlineText", 0, "#E6E8F8");
    insCell(arow, biblio_name, "headlineText", "60%", "#E6E8F8");
    insCell(arow, "Новая запись", "headlineText", "27%", "#E6E8F8");
	window.close();
}

function delrows() {
    var arr_del_me = d.getElementsByName('del_me[]');
    var len = arr_del_me.length;
    var tab = d.getElementById("tbadd");
    var tb = tab.getElementsByTagName('TBODY')[0];

    var chds = new Array(len);
    var ids = new Array(len);

    for(var i=0; i<len; i++) {
        chds[i] = arr_del_me[i].checked;
        ids[i] = arr_del_me[i].value;
    }

    for(var i=0; i<len; i++)
        if(chds[i])
            tb.removeChild(d.getElementById("row"+ids[i]));
}

function setCookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );
  else
        cookie_string += "; path=/";

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );

  if ( secure )
        cookie_string += "; secure";

  document.cookie = cookie_string;
}

 function getCookie ( cookie_name )
{
  var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );

  if ( results )
    return ( unescape ( results[1] ) );
  else
    return null;
}
